#include<bits/stdc++.h>
using namespace std;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin>>t;
    int chao=0;
    int close=0;
    long long n,m,l,v;
    for(int i=0;i<t;i++){
        chao=0;
        cin>>n>>m>>l>>v;
        long long pos[m];
        int fei;
        int su;
        int indis;
        int a;
        int yan[n];
        float pos1[n];
        int linshiyanzheng=0;
        int ayanzheng=0;
        int teshuchaosu=0;
        for(int x=0;x<n;x++){
            yan[x]=0;
            pos1[x]=0;
        }
        for(int j=0;j<n;j++){
            cin>>indis;
            cin>>su;
            cin>>a;
            if(a==0){//tepan,a=0huibuhuichaosu
                if(su>v){
                teshuchaosu=1;
                chao++;
                close=m-1;
                }else{
                    close=m;
                }
            }else{
                ayanzheng=1;
                if(a>0){
                    float vmax=0;
                    float chaowei=0;
                    vmax=sqrt(su*su+2*a*(l-indis));
                    if(vmax>v){
                        yan[j]=1;
                        pos1[j]=(v*v-su*su)/(2*a)+indis;
                    }
                }else{//a<0zuobuchulai,suibainluanxiele
                    if(su>v){
                        chao++;
                        close++;
                    }
                }
            }

        }
        for(int y=0;y<m;y++){
            cin>>pos[y];
        }
        sort(pos,pos+m);
        for(int k=0;k<m;k++){
            if(yan[k]==1){
                if(pos1[k]<=pos[k]){
                    chao++;//beizhuale
                    linshiyanzheng=1;
                }
            }
        }
        if(ayanzheng==0){
            if(teshuchaosu==1){
                close=m-1;
            }else{
                close=m;
            }
        }else{
            if(linshiyanzheng==0){
            close=m;
        }else{
            close=m-1;
        }
        }
        cout<<chao<<" "<<close<<endl;
    }
    return 0;
}

